package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xmy.cultivate.entity.DormRoom;
import com.xmy.cultivate.entity.DormRoomMember;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 宿舍成员 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2025-03-02
 */
public interface DormRoomMemberMapper extends BaseMapper<DormRoomMember> {


    @Select({"<script>",
            "SELECT",
            "d.*,",
            "s.`name` AS member_name",
            "FROM",
            "dorm_room_member d",
            "LEFT JOIN staff s ON d.teacher_id = s.id",
            "WHERE",
            "1=1",
            "AND d.room_id = ${roomId} ",
            "</script>"})

    public IPage<DormRoomMember> getDormRoomMemberList(IPage<DormRoomMember> page, @Param("roomId") String roomId );


    @Select({"<script>",
            "SELECT",
            "s.name AS member_name,",
            "s.id",
            "FROM",
            "staff s",
            "LEFT JOIN dorm_room_member d ON d.teacher_id = s.id" ,
            "<if test='roomIds != null and roomIds !=&apos;&apos;'>",
                    " AND d.room_id IN (#{roomIds})",
            "</if>",
//            "<foreach item='roomId' index='index' collection='roomIds' open='(' separator=',' close=')'>",
//            "#{roomId}",
//            "</foreach>",
            "WHERE",
            "s.sex = #{sexType}",
            "AND s.status = 1",
            "AND s.deleted = 0",
            "AND d.id IS NULL",
            "</script>"})
    public List<DormRoomMember> getDormRoomMemberListBySexType(@Param("sexType") String sexType, @Param("roomIds") String roomIds);

}
